﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Totoro.ORMapping;
using NHibernate;
using Model.Entities ;
using Totoro.Core;
using Bussiness;
using System.Text; 


namespace PerssionCenterServices.Account
{
    public partial class RegiseterPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache); 

        }
        protected void RegisterClick(object sender, EventArgs e) 
        {
           
            Model.Entities.User u = new Model.Entities.User();
            u.LogonName = txtLogonName.Value.Trim();
            u.PassWord =  Cryption.EnCryption ( txtPassword.Value);
            u.NickName = txtNickName.Value.Trim();
            u.CreateTime = DateTime.Now;
            u.EndTime = DateTime.MaxValue;
            u.UpdateTime = u.CreateTime;
            if (CheckUserInfo ())
             {
                NHHelper.SaveOjb(u);
                this.txtLogonName.Value = string.Empty;
                this.txtNickName.Value = string.Empty;
                this.tbRegister.Visible = false;
                HttpContext.Current.Response.Redirect("RegisterSuccess.aspx?name="+u.LogonName +"&nick="+u.NickName);
            }
        }
        private bool CheckUserInfo()
        {
            StringBuilder sb = new StringBuilder();
            if (Permission.CheckIsUserExits(txtLogonName.Value))
                sb.AppendLine("用户名已经存在!");
            if (string.IsNullOrEmpty(this.txtPassword.Value))
                sb.AppendLine("密码不能为空!");
            if (string.IsNullOrEmpty(txtNickName.Value))
                sb.AppendLine("昵称不能为空!");
            if (sb.Length > 0)
            {
                //lblMsg.Text = sb.ToString();
                return false;
            }
            {
                //lblMsg.Text = string.Empty; 
                return true; 
            }


        }
    }
}